package com.niit.service.impl;

import java.util.List;

import com.niit.bean.News;
import com.niit.dao.NewsDao;
import com.niit.dao.impl.NewsDaoImpl;
import com.niit.service.NewsService;
import com.niit.utils.Page;

public class NewsServiceImpl implements NewsService {
	private NewsDao dao = new NewsDaoImpl();
	@Override
	public int add(News t) {
		return dao.add(t);
	}

	@Override
	public int delete(News t) {
		return dao.delete(t);
	}

	@Override
	public int update(News t) {
		return dao.update(t);
	}

	@Override
	public Page<News> getPage(String pagenum, String url) {
		int total = dao.findTotal();//查出总记录数
		Page<News> page = null;
		if(pagenum == null){
			page = new Page<News>(total,1);
		}else{
			page = new Page<News>(total, Integer.parseInt(pagenum));
		}
		List<News> list = dao.findAll(page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}
	
	
	public Page<News> getPage(String pagenum, String url, String kind) {
		int total = dao.findTotal();//查出总记录数
		Page<News> page = null;
		if(pagenum == null){
			page = new Page<News>(total,1);
		}else{
			page = new Page<News>(total, Integer.parseInt(pagenum));
		}
		List<News> list = dao.findByKind(kind, page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}

	@Override
	public News findById(String id) {
		return dao.findById(id);
	}

}
